<template>
    <div class="box">
        <div class="bar">
            <div :class="['item', item.isActive? 'is-active':'']"
            v-for="item in list" 
            :key="item.id"
            @click="handler(item.id)">
            <span :class="item.icon" class="item-icon"></span>
            <span>{{ item.label }}</span>
        </div>
        </div>

    </div>
</template>

<script setup>
import { ref } from 'vue';
import { nanoid } from 'nanoid';

const list = ref([
    {
        id:nanoid(6),
        label:'购物车',
        icon:'fas fa-bicycle',
        isActive:false
    },
    {
        id:nanoid(6),
        label:'收藏',
        icon:'fas fa-ad',
        isActive:false
    },
    {
        id:nanoid(6),
        label:'首页',
        icon:'fas fa-align-justify',
        isActive:true
    },
    {
        id:nanoid(6),
        label:'设置',
        icon:'fas fa-asterisk',
        isActive:false
    },
    {
        id:nanoid(6),
        label:'我的',
        icon:'fas fa-address-book',
        isActive:false
    },
]);

const handler = id =>{
    list.value.forEach(item =>{
        item.isActive = item.id == id;
    });
}

</script>

<style lang="scss" scoped>
.box{
    width: 100%;
    height: 500vh;
}

.is-active{
    color: blue;
}
.bar{
    width: 100%;
    // height: 10vh; //让高度被内容撑开
    // border: 1px solid;

    position: fixed;
    bottom: 0px;

    display: flex;
    justify-content: space-evenly;
    align-items: center;

    width: 100%;
    box-shadow: 0 0 10px rgba(0,0,0,0.3);

}

.item{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    padding: 15px;

    &-icon{
        // 调整图标大小
        font-size: 25px;
    }
}

</style>